from django.http.response import HttpResponse, JsonResponse
from django.http.request import HttpRequest
from .models import FeedBack
from django.db import connection
from django.shortcuts import render
import json


# Create your views here.

def my_sql(sql):
    with connection.cursor() as cursor:
        raw = cursor.execute(sql)
    return raw


def hello(request):
    html = "hello world"

    return HttpResponse(html)


def submit(request: HttpRequest):
    html = request.method
    url_params = request.path
    query_str = request.GET
    headers = request.headers
    body = request.body
    if request.method == "POST":
        data = json.loads(request.body)
    obj = FeedBack()
    obj.quality = data["quality"]
    obj.save()

    # 执行原始的sql语句
    sql = "select * from beifan"
    res = my_sql(sql)
    print(res)

    return  JsonResponse({"code":200,"data":data,"message":"ok"})

def result(request):
    return "success"
